package cn.doitedu.javase.aviator;

import com.googlecode.aviator.AviatorEvaluator;
import com.googlecode.aviator.Expression;

import java.util.HashMap;

public class TestAviator {

    public static void main(String[] args) {

        //String exp = "a-b*c";
        String exp = "a>b?a+b:b+c";
        int a = 10;
        int b = 20;
        int c = 30;

        HashMap<String, Object> dataMap = new HashMap<>();
        dataMap.put("a",a);
        dataMap.put("b",b);
        dataMap.put("c",c);

        // 编译表达式
        Expression expression = AviatorEvaluator.compile(exp);
        // 调用表达式对象的execute方法，并传入表达式需要的数据
        Object result = expression.execute(dataMap);

        System.out.println(result);


    }


}
